package com.xcity.game.guild.gevent;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.xcity.db.entity.Player;

public class GuildEvents {
	
	public static int MAX_COUNT = 20;
	
	protected List<GuildEvent> events;
	
	public GuildEvents(){
	}
	
	public GuildEvents(List<GuildEvent> eventList){
		this.events = eventList != null? eventList : new ArrayList<GuildEvent>();
	}
	
	public List<GuildEvent> getEvents() {
		return events;
	}

	public void setEvents(List<GuildEvent> events) {
		this.events = events;
	}
	
	public void addNewGuildEvents(int type, long sourceId, long targetId){
		if(this.events.size() >= MAX_COUNT){
			int count = this.events.size() - MAX_COUNT + 1;
			for(int i = 0; i < count; i++){
				this.events.remove(0);
			}
		}
		GuildEvent event = new GuildEvent(type, sourceId, targetId);
		this.events.add(event);
	}
	
	@Override
	public String toString(){
		return JSON.toJSONString(events);
	}
}
